package org.orbis.memorymanager;

import org.orbis.structure.LookupPointer;

public class ContentInformation{
	private LookupPointer current, next, previous;
	private int index;
	private long ID;
	private int skipPoint;
	private boolean isFound;
	private boolean appendSkipPointer;
	private SkipState skipState;

	public enum SkipState{
		behindFirst, first, middle, last, behindLast, none;
	}
	
	private ContentInformation() {}

	public ContentInformation(LookupPointer current){
		this.current = current;
		this.isFound = (current != null && !current.equals(LookupPointer.EMPTY));
		this.skipPoint = -1;
		this.skipState = SkipState.none;
	}
	
	public static ContentInformation getDefault() {
		ContentInformation info = new ContentInformation();
		
		info.current = LookupPointer.valueOf(-1, -1);
		info.next = LookupPointer.valueOf(-1, -1);
		info.previous = LookupPointer.valueOf(-1, -1);
		info.skipPoint = -1;
		info.skipState = SkipState.none;
		
		return info;
	}

	public ContentInformation skipptr(int index){
		this.skipPoint = index;
		return this;
	}

	public ContentInformation ID(long ID){
		this.ID = ID;
		return this;
	}
	
	public ContentInformation index(int index) {
		this.index = index;
		return this;
	}

	public int getSkipIndex(){
		return skipPoint;
	}

	public ContentInformation appendSkip(boolean isAppend){
		this.appendSkipPointer = isAppend;
		return this;
	}

	public ContentInformation behindFirst(){
		this.skipState = SkipState.behindFirst;
		return this;
	}

	public ContentInformation first(){
		this.skipState = SkipState.first;
		return this;
	}

	public ContentInformation middle(LookupPointer previous){
		this.skipState = SkipState.middle;
		this.previous = previous;
		return this;
	}

	public ContentInformation last(LookupPointer previous){
		this.skipState = SkipState.last;
		this.previous = previous;
		return this;
	}

	public ContentInformation behindLast(LookupPointer previous){
		this.skipState = SkipState.behindLast;
		this.previous = previous;
		return this;
	}

	public ContentInformation current(LookupPointer current){
		this.current = current;
		return this;
	}

	public ContentInformation next(LookupPointer next){
		this.next = next;
		return this;
	}

	public LookupPointer getCurrent(){
		return current;
	}

	public LookupPointer getNext(){
		return next;
	}

	public long getID(){
		return ID;
	}
	
	public int getIndex() {
		return index;
	}

	public boolean isFound(){
		return isFound;
	}

	public boolean isBehindFirst(){
		return skipState == SkipState.behindFirst;
	}

	public boolean isFirst(){
		return skipState == SkipState.first;
	}

	public boolean isMiddle(){
		return skipState == SkipState.middle;
	}

	public boolean isLast(){
		return skipState == SkipState.last;
	}

	public boolean isBehindLast(){
		return skipState == SkipState.behindLast;
	}

	public LookupPointer getPrevious(){
		return previous;
	}

	public boolean isAppendSkipPointer(){
		return appendSkipPointer;
	}

	public boolean isInContent(){
		return(skipState != SkipState.behindFirst || skipState == SkipState.behindLast);
	}
}
